using System.IO;
using System.Xml.Serialization;
using ChordCreator.ViewServices;

namespace ChordCreator.Services.ConfigurationServices
{
    public class XmlConfiguration
    {
        internal static readonly char[] Seperators = new[] { ';', '.', ',', ' ', '\t', '\r', '\n' };
        private static XmlConfiguration instance_;

        private ConfigurationHandler handlerer_;
        private const string ConfigurationFileKey = "configuration.xml";

        public ConfigurationHandler Handlerer
        {
            get { return handlerer_; }
        }

        public static XmlConfiguration Instance
        {
            get
            {
                if (instance_ == null)
                {
                    instance_ = new XmlConfiguration();
                }
                return instance_;
            }
        }

        private XmlConfiguration()
        {
            Initialize();
        }
        public void Initialize()
        {
            XmlSerializer mySerializer = new
                XmlSerializer(typeof(ConfigurationHandler));
            if (!File.Exists(ConfigurationFileKey))
            {
                MessageHelper.ShowCriticalError("{0} file not found.", "configuration.xml");
            }
            using (StreamReader reader = new StreamReader(ConfigurationFileKey))
            {
                handlerer_ = (ConfigurationHandler)mySerializer.Deserialize(reader);
            }
        }
        
    }
}